package com.lianda.mutiple.pattern.aobj.example;

import com.lianda.mutiple.pattern.future.Future;

import java.util.Map;

public class FindOrderDetailsMessage extends MethodMessage {

    public FindOrderDetailsMessage(Map<String, Object> params, OrderService orderService) {
        super(params, orderService);
    }

    @Override
    public void execute() {
        Future<String> realFuture = orderService.findOrderDetails((Long)params.get("orderId"));
        ActiveFuture<String> activeFuture = (ActiveFuture<String>)params.get("activeFuture");
        try {
            //阻塞等待结果
            String result = realFuture.get();
            //通过finish传递结果给activeFuture
            activeFuture.finish(result);
        } catch (InterruptedException e) {
            activeFuture.finish(null);
        }
    }
}
